package observer;

import java.util.ArrayList;

public class Child {
    private boolean cry = false;

    // 观察者队列
    private ArrayList<Observer> list = new ArrayList<>();

    public boolean isCry(){
        return cry;
    }

    public void wakeup(){
        System.out.println("小孩子起来");
        cry = true;
        // 小孩醒了调用观察者队列
        WeakupEvent <Child>weakupEvent = new WeakupEvent();
        weakupEvent.weakupEvent(System.currentTimeMillis(), "wakeup", this);

        doAll(weakupEvent);
    }

    public void doAll(Events events){
        for(Observer item:list){
            item.call(events);
        }
    }

    // 被观察者 注册观察者
    public Child registerObserver(Observer observer){
        list.add(observer);
        return this;
    }
}
